import request from '@/utils/request'

export function getList(type, params) {
  let url = ''
  switch (type) {
    case 'getBuff':
      url = 'getBuff'
      break
    case 'getCilpMoney':
      url = 'getCilpMoney'
      break
    case 'getCapitalMoney':
      url = 'getCapitalMoney'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'get',
      params
    })
      .then(res => {
        resolve(res)
      })
      // eslint-disable-next-line handle-callback-err
      .catch(error => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve(data)
      })
  })
}

export function addOne(type, data) {
  let url = ''
  switch (type) {
    case 'getBuffAdd':
      url = 'getBuffAdd'
      break
    case 'getBuffAddList':
      url = 'getBuffAddList'
      break
    case 'getCilpMoneyAdd':
      url = 'getCilpMoneyAdd'
      break
    case 'getCilpMoneyAddList':
      url = 'getCilpMoneyAddList'
      break
    case 'getCapitalMoneyAdd':
      url = 'getCapitalMoneyAdd'
      break
    case 'getCapitalMoneyAddList':
      url = 'getCapitalMoneyAddList'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function updateOne(type, data) {
  let url = ''
  switch (type) {
    case 'getBuffUpdate':
      url = 'getBuffUpdate'
      break
    case 'getBuffBatchUpdate':
      url = 'getBuffBatchUpdate'
      break
    case 'getBuffCheck':
      url = 'getBuffCheck'
      break
    case 'getBuffSync':
      url = 'getBuffSync'
      break
    case 'getCilpMoneyUpdate':
      url = 'getCilpMoneyUpdate'
      break
    case 'getCilpMoneyBatchUpdate':
      url = 'getCilpMoneyBatchUpdate'
      break
    case 'getCilpMoneyCheck':
      url = 'getCilpMoneyCheck'
      break
    case 'getCilpMoneySync':
      url = 'getCilpMoneySync'
      break
    case 'getCapitalMoneyUpdate':
      url = 'getCapitalMoneyUpdate'
      break
    case 'getCapitalMoneyBatchUpdate':
      url = 'getCapitalMoneyBatchUpdate'
      break
    case 'getCapitalMoneyCheck':
      url = 'getCapitalMoneyCheck'
      break
    case 'getCapitalMoneySync':
      url = 'getCapitalMoneySync'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function deleteOne(type, data) {
  let url = ''
  switch (type) {
    case 'getBuffDelete':
      url = 'getBuffDelete'
      break
    case 'getCilpMoneyDelete':
      url = 'getCilpMoneyDelete'
      break
    case 'getCapitalMoneyDelete':
      url = 'getCapitalMoneyDelete'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}
